﻿package com.hh.bss.oa.service.impl;

import java.util.Date;

import com.hh.bss.oa.entity.OaMeetingRoomTaking;
import com.hh.bss.util.DateHelper;
import com.hh.bss.util.StringHelper;

public class Test16 {
	private boolean isConflict(OaMeetingRoomTaking newt, OaMeetingRoomTaking oldt){
		
		String newOrderDateStr=DateHelper.toString(newt.getOrderDate(), "yyyyMMdd");
		String oldOrderDateStr=DateHelper.toString(oldt.getOrderDate(), "yyyyMMdd");
		
		java.util.Date newOrderDate = DateHelper.toDate(DateHelper.toString(newt.getOrderDate(), "yyyyMMdd"), "yyyyMMdd");
	    java.util.Date oldOrderDate = DateHelper.toDate(DateHelper.toString(oldt.getOrderDate(), "yyyyMMdd"), "yyyyMMdd");
		
		int newTimeBeginInt=StringHelper.parseInt(DateHelper.toString(newt.getBeginDt(), "HHmm"), 0);
		int newTimeEndInt=StringHelper.parseInt(DateHelper.toString(newt.getEndDt(), "HHmm"), 0);
		int oldTimeBeginInt=StringHelper.parseInt(DateHelper.toString(oldt.getBeginDt(), "HHmm"), 0);
		int oldTimeEndInt=StringHelper.parseInt(DateHelper.toString(oldt.getEndDt(), "HHmm"), 0);
		
		//新的预订日期不能超过31天
		int ds=DateHelper.getDiffDay(newt.getOrderDate(), new Date());
		int diffd=DateHelper.getDiffDay(newt.getOrderDate(), oldt.getOrderDate());
		if (ds>31) return true;
		
		//比较会议室
		
		
		//新的是指定天的
		if (newt.getPeriodType().intValue()==1){
			//旧的是一天的
			if (oldt.getPeriodType().intValue()==1){
				
				if (newOrderDateStr.equals(oldOrderDateStr)){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;					
				}
				
			}else if (oldt.getPeriodType().intValue()==2){
				//旧的是每天 
				if (oldt.getOrderDate().after(newt.getOrderDate())||oldt.getOrderDate().equals(newt.getOrderDate())){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;					
				}
			}else if (oldt.getPeriodType().intValue()==3){
				//旧的是每周的
				if (diffd%7==0&&newt.getOrderDate().after(oldt.getOrderDate())){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;
				}
			}else if (oldt.getPeriodType().intValue()==4){
				//旧的是每两周的
				if (diffd%14==0&&newt.getOrderDate().after(oldt.getOrderDate())){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;
				}
			}
			
		}
		//新的是每天的
		else if (newt.getPeriodType().intValue()==2){
			//旧的是一天的
			if (oldt.getPeriodType().intValue()==1){
			
				if (oldOrderDate.equals(newOrderDate)||oldOrderDate.after(newOrderDate)){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;					
				}
				
			}else if (oldt.getPeriodType().intValue()==2){
				//旧的是每天 			
				if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;					
			}else if (oldt.getPeriodType().intValue()==3){
				//旧的是每周的				
				if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;				
			}else if (oldt.getPeriodType().intValue()==4){
				//旧的是每两周的				
				if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;				
		    }
		}
		//新的是每周的
		else if (newt.getPeriodType().intValue()==3){
			//旧的是一天的
			if (oldt.getPeriodType().intValue()==1){
			
				
				if (diffd%7==0&&(oldOrderDate.equals(newOrderDate)||oldOrderDate.after(newOrderDate))){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;
				}
				
			}else if (oldt.getPeriodType().intValue()==2){
				//旧的是每天 			
				if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;					
			}else if (oldt.getPeriodType().intValue()==3){
			   //旧的是每周的
				
				if (diffd%7==0){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;
				}
			}else if (oldt.getPeriodType().intValue()==4){
			   //旧的是每周的				
				if (diffd%14==0){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;
				}
			}	
				
			
		}
		//新的是两周的
		else if (newt.getPeriodType().intValue()==4){
			//旧的是一天的
			if (oldt.getPeriodType().intValue()==1){			
				
				if (diffd%14==0&&(oldOrderDate.equals(newOrderDate)||oldOrderDate.after(newOrderDate))){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;
				}
				
			}else if (oldt.getPeriodType().intValue()==2){
				//旧的是每天 			
				if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;					
			}else if (oldt.getPeriodType().intValue()==3){
			   //旧的是每周的
				
				if (diffd%14==0){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;
				}
			}else if (oldt.getPeriodType().intValue()==4){
			   //旧的是每周的				
				if (diffd%14==0){
					if ((oldTimeBeginInt<=newTimeBeginInt&&oldTimeEndInt>=newTimeBeginInt)||(oldTimeBeginInt<=newTimeEndInt&&oldTimeEndInt>=newTimeEndInt)) return true;
				}
			}	
		}
		
		
		return false;
	}
	public static void main(String[] arg){
		OaMeetingRoomTaking a=new OaMeetingRoomTaking();
		OaMeetingRoomTaking b=new OaMeetingRoomTaking();
		a.setPeriodType(new Integer(2));
		a.setOrderDate(DateHelper.toDate("20130201", "yyyyMMdd"));
		a.setBeginDt(DateHelper.toDate("20130201 100000", "yyyyMMdd HHmmss"));
		a.setEndDt(DateHelper.toDate("20130201 110000", "yyyyMMdd HHmmss"));
		
		b.setPeriodType(new Integer(1));
		b.setOrderDate(DateHelper.toDate("20130202", "yyyyMMdd"));
		b.setBeginDt(DateHelper.toDate("20130201 100101", "yyyyMMdd HHmmss"));
	    b.setEndDt(DateHelper.toDate("20130201 120000", "yyyyMMdd HHmmss"));
	    Test16 t=new Test16();
	    //System.out.println(t.isConflict(a, b));
	    System.out.println(DateHelper.toDate("12:00", "HH:mm"));
	    
	    String newmeetings="1";
	    String oldmeetings="1";
	    boolean roomHasConflict=false;
	   
		String[] newms=newmeetings.split(",");
		String[] oldms=oldmeetings.split(",");
		 System.out.println(newms+"--"+oldms);
		for(int i=0;i<newms.length;i++){
			for(int j=0;j<oldms.length;j++){
				 System.out.println("conflict");
				//if (newms[i].equals(oldms[j]))  System.out.println("conflict");
			}
		}
	    
	}

}
